package cn.madis.ymcc.service.impl;

import cn.madis.ymcc.domain.Course;
import cn.madis.ymcc.domain.CourseChapter;
import cn.madis.ymcc.mapper.CourseChapterMapper;
import cn.madis.ymcc.service.ICourseChapterService;
import cn.madis.ymcc.service.ICourseService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 课程章节 ， 一个课程，多个章节，一个章节，多个视频 服务实现类
 * </p>
 *
 * @author Zt
 * @since 2022-08-07
 */
@Service
public class CourseChapterServiceImpl extends ServiceImpl<CourseChapterMapper, CourseChapter> implements ICourseChapterService {

    @Autowired
    private ICourseService courseService;
    /**
     *
     * @param entity
     * @return
     */
    @Override
    public boolean insert(CourseChapter entity) {
        super.insert(entity);
        Course course = courseService.selectById(entity.getCourseId());
        Integer chapterCount = course.getChapterCount();
        if (chapterCount != null){
            course.setChapterCount(chapterCount+1);
        }else {
            course.setChapterCount(1);
        }

        return courseService.insert(course);

    }
}
